#include<iostream>
#include"http.h"


void Get(Request& req,Response& rep){
    std::string rep_str; 
    //组装响应行
    rep_str.append(rep.GetVersion());
    rep_str.append(" ");
    rep_str.append(std::to_string(rep.GetStatus())+"\r\n");
    //添加响应头
    for(auto& header:rep.GetHeaders()){
        rep_str.append(header.first);
        rep_str.append(": ");
        rep_str.append(header.second);
        rep_str.append("\r\n");
    }
    rep_str.append("\r\n");
    //添加响应体
    rep_str.append(rep.GetBody());
    LOG(ly::LogLevel::DEBUG)<<rep_str;
}
void Post(Request& req,Response& rep ){
    LOG(ly::LogLevel::DEBUG)<<"Post";
}
void Put(Request& req,Response& rep ){
    LOG(ly::LogLevel::DEBUG)<<"Put";
}
void Delete( Request& req,Response& rep){
    LOG(ly::LogLevel::DEBUG)<<"Delete";
}

int main(){
    HttpServer server(8081,1,30);
    server.SetGet(bind(&Get,std::placeholders::_1,std::placeholders::_2));
    server.SetPost(bind(&Post,std::placeholders::_1,std::placeholders::_2));
    server.SetPut(bind(&Put,std::placeholders::_1,std::placeholders::_2));
    server.SetDelete(bind(&Delete,std::placeholders::_1,std::placeholders::_2));
    server.Start();
    return 0;
}